﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarriorRush.GameDynamics.Characters;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using WarriorRush.GameDynamics.Utilities;
using WarriorRush.GameDynamics;


namespace WarriorRush
{
    public  class TextureManager
    {
        public Dictionary<CharacterTypes, Texture2D> CharacterTextures;
        public Point StandardSize;
        public Texture2D Square;
        private Rectangle boundingRectangle;
        public Dictionary<HighlightType, Texture2D> HighlightTextures;
        private Rectangle highlightBoundingRecangle;
        public Dictionary<int, SpriteFont> Fonts;
        public Dictionary<EffectType, Point> EffectTextureLocations;
        public Texture2D EffectTextures;
        private Rectangle effectBoundingRectangle;
        public float CharacterScaling;
        public Texture2D DoneButton;
        public Rectangle DoneBounding;
        
        public TextureManager(ContentManager Content, Dictionary<CharacterTypes, String> textures, Point size, Dictionary<HighlightType, String> highlight)
        {
            CharacterTextures =  textures.ToDictionary(f=>f.Key,f=> Content.Load<Texture2D>(f.Value));
            HighlightTextures = highlight.ToDictionary(f => f.Key, f => Content.Load<Texture2D>(f.Value));
            StandardSize = size;
            boundingRectangle = new Rectangle(0, 0, size.X, size.Y);
            highlightBoundingRecangle = new Rectangle(0, 0, 70, 70);
            CharacterScaling = 2.5f;
            DoneBounding = new Rectangle(0, 0, 300, 300);

        }

        public void DrawCharacter(SpriteBatch spriteBatch,CharacterTypes type,  Vector2 location )
        {
            spriteBatch.Draw(CharacterTextures[type],location,boundingRectangle , new Color(256, 256, 256),0,Vector2.One,CharacterScaling,SpriteEffects.None,0);
        }

        public void DrawSelectable(SpriteBatch spriteBatch, HighlightType type, Vector2 location)
        {
            
            spriteBatch.Draw(HighlightTextures[type], location, highlightBoundingRecangle, new Color(256, 256, 256), 0, Vector2.One, 2.3f, SpriteEffects.None, 0);
        }

        public void SetFonts(ContentManager content, Dictionary<int,String> fonts)
        {
            Fonts = fonts.ToDictionary(f => f.Key, f => content.Load<SpriteFont>(f.Value));
        }

        public void GetEffectTexture(ContentManager content, string fileName)
        {
            EffectTextures = content.Load<Texture2D>(fileName);
        }

        public void DrawText(SpriteBatch spriteBatch, Vector2 position ,string text, int size, Color rgb)
        {
            spriteBatch.DrawString(Fonts[size], text,position, rgb);
        }

        public void DrawEffect(SpriteBatch spriteBatch, EffectType type, Vector2 location)
        {
            if(type != EffectType.Null)
                spriteBatch.Draw(EffectTextures, location, new Rectangle(25 * EffectTextureLocations[type].X, 25 * EffectTextureLocations[type].Y, 25, 25), new Color(255, 255, 255));
        }

        public void GetDoneButton(ContentManager content, string name)
        {
            DoneButton = content.Load<Texture2D>(name);

        }

        public void DrawDownButton(SpriteBatch spriteBatch, Rectangle position)
        {
            spriteBatch.Draw(DoneButton, position, new Color(255, 255, 255));
        }

    }
}
